/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Engine2D.level.tile;

import Engine2D.entity.Entity;
import Engine2D.entity.Player;
import Engine2D.graphics.GLColour;
import Engine2D.graphics.GLSpriteSheet;
import Engine2D.level.Level;
import Engine2D.graphics.GLImage;
import Engine2D.graphics.particle.GLParticleSystem;

/**
 *
 * @author Garys
 */
public class OreTile extends Tile {

    /**
     * 
     * @param id
     * @param spriteSheet
     * @param sizeX
     * @param sizeY
     */
    public OreTile(int id, GLSpriteSheet spriteSheet, int sizeX, int sizeY) {
        super(id, sizeX, sizeY);
        this.image = spriteSheet;
    }

    /**
     * 
     * @param level
     * @param x
     * @param y
     */
    public void render(Level level, int x, int y, int xt, int yt) {
        image.drawTile(x, y,256f, 480f);
    }

    /**
     * 
     * @param level
     * @param x
     * @param y
     * @param e
     * @return
     */
    @Override
    public boolean mayPass(Level level, int x, int y, Entity e) {
        return false;
    }

    /**
     * 
     * @param level
     * @param x
     * @param y
     * @param entity
     * @param damage
     * @param dir
     */
    @Override
    public void hurt(Level level, int x, int y, Entity entity, int damage, char dir) {
        damage += level.getData(x, y);
        if (damage >= 50) {

            int yo = 16;
            int xo = 16;
            int r = 32;

            if (dir == 'u') {
                level.addParticleSystem(new GLParticleSystem(entity.x + xo, entity.y + yo - r, 1, 10000l, 1000l, 1f, -1f, 0.01f, GLColour.WHITE, "ore"));
            }
            if (dir == 'd') {
                level.addParticleSystem(new GLParticleSystem(entity.x + xo, entity.y + yo + r, 1, 10000l, 1000l, 1f, -1f,0.01f, GLColour.WHITE, "ore"));
            }
            if (dir == 'l') {
                level.addParticleSystem(new GLParticleSystem(entity.x + xo - r, entity.y + yo, 1, 10000l, 1000l, 1.5f, -1.5f, 0.01f,GLColour.WHITE, "ore"));
            }
            if (dir == 'r') {
                level.addParticleSystem(new GLParticleSystem(entity.x + xo + r, entity.y + yo, 1, 10000l, 1000l, 1f, -1f,0.01f, GLColour.WHITE, "ore"));
            }
            ((Player)entity).gemsCollected++;
            level.setTile(x, y, TileManager.tunnel, 0);
        }
        
        
        level.setData(x, y, damage);
    }
}
